package main

import "fmt"

// 13 | 参数传递：值、引用及指针之间的区别？
func main() {

	add := address{province: "北京", city: "北京"}
	printString(add)
	printString(&add)

	var si fmt.Stringer = address{province: "陕西", city: "西安"}
	printString(si)
	//sip := &si
	//printString(sip)

	p := person{name: "曹靖", age: 18}
	fmt.Printf("main函数：p的内存地址为 %p\n", &p)
	modifyPerson(p)
	printString(p)

	modifyPerson2(&p)
	printString(p)

	m := make(map[string]int)
	m["曹靖"] = 28
	fmt.Printf("main函数：m的内存地址为 %p\n", m)
	fmt.Println("曹靖的年龄为", m["曹靖"])
	modifyMap(m)
	fmt.Println("曹靖的年龄为", m["曹靖"])

}

type address struct {
	province string
	city     string
}

type person struct {
	name string
	age  int
}

// 以值类型实现接口的时候【类型本身】和【该类型的指针类型】都实现了该接口
func (p person) String() string {
	return fmt.Sprintf("the name is %s,age is %d", p.name, p.age)
}

func (addr address) String() string {
	return fmt.Sprintf("the addr is %s%s", addr.province, addr.city)
}

func printString(s fmt.Stringer) {
	fmt.Println(s.String())
}

func modifyPerson(p person) {
	fmt.Printf("modifyPerson函数：p的内存地址为 %p\n", &p)
	p.name = "靖哥哥"
	p.age = 28
}

func modifyPerson2(p *person) {
	fmt.Printf("modifyPerson2函数：p的内存地址为 %p\n", p)
	p.name = "靖哥哥"
	p.age = 28
}

func modifyMap(p map[string]int) {
	fmt.Printf("main函数：m的内存地址为%p\n", p)
	p["曹靖"] = 18
}
